library(ggplot2)
library(openxlsx)



#data for point estimates
data <- read.xlsx("C:\\Users\\elis\\Jonas\\imges1\\Paper 05 Transnational Voting\\2dimcoeffplot_theor\\2dim_coeffplot.xlsx")

data$coeff_mean <- as.numeric(data$coeff_mean)
data$coeff_net <- as.numeric(data$coeff_net)
data$low_mean <- as.numeric(data$low_mean)
data$up_mean <- as.numeric(data$up_mean)
data$low_net <- as.numeric(data$low_net)
data$up_net <- as.numeric(data$up_net)

#data for confidence intervals 
data_long <- read.xlsx("C:\\Users\\elis\\Jonas\\imges1\\Paper 05 Transnational Voting\\2dimcoeffplot_theor\\2dim_coeffplot_long (version ac).xlsx")

data_long$coeff_net <- as.numeric(data_long$coeff_net)
data_long$con_mean <- as.numeric(data_long$con_mean)
data_long$coeff_mean <- as.numeric(data_long$coeff_mean)
data_long$con_net <- as.numeric(data_long$con_net)


#plot
ggplot(data, aes(label = coeff_lb)) +
  geom_point(aes(x = coeff_net, y = coeff_mean), shape = 15, size = 2) +
  scale_shape_identity() +
  geom_text(aes(x = coeff_net, y = coeff_mean), hjust = -0.17, vjust = -0.5) +
  geom_point(data = data_long, aes(x = coeff_net, y = con_mean), shape = 32) +
  geom_line(data = data_long, aes(x = coeff_net, y = con_mean, group = coeff_var)) +
  geom_point(data = data_long, aes(x = con_net, y = coeff_mean), shape = 32) +
  geom_line(data = data_long, aes(x = con_net, y = coeff_mean, group = coeff_var)) +
  theme_minimal() +
  geom_hline(yintercept = 0, linetype = "dotted") +
  geom_vline(xintercept = 0, linetype = "dotted") +
  annotate("text", x = -0.48, y = -0.19, label = "deactivating", size = 4.5) +
  annotate("text", x = -0.48, y = 0.41, label = "activating", size = 4.5) +
  xlim(-0.5, 0.5) +
  xlab("Net political interest") +
  ylab("Mean political interest") +
  theme(panel.border = element_rect(colour = "black", fill = NA, size = 1),
       axis.text.x = element_text(size = 13, colour = "black"),
       axis.text.y = element_text(size = 13, colour = "black"),
       axis.title.x = element_text(size = 13),
       axis.title.y = element_text(size = 13))
